//
// Group Memeber: Xiaodi Wu(xiaodiwu), Mac Witlzer(macclain)
//


#ifndef BUFMAP_H
#define BUFMAP_H

#include "db.h"
#include <map>

using namespace std;

typedef map<int, unsigned int>* PageMapPtr;
typedef map<int, unsigned int> PageMap;
typedef map<int, unsigned int>::iterator PageMapItr;

typedef map<File*, PageMapPtr> FileMap;
typedef map<File*, PageMapPtr>::iterator FileMapItr;

// class to keep track of pages in the buffer pool
class BufMap
{
private:
  FileMap *myFileMap;
 
public:

  BufMap(); // Constructor
  ~BufMap();  // Deconstructor

  // insert entry into buffer pool, mapping (file,pageNo) to frameNo.
  // return OK or BUFMAPERROR if an error occurred.
  const Status insert(File* file, const int pageNo, const unsigned int frameNo);

  // Check if (file,pageNo) is currently in the buffer pool and return frameNo
  // if found.  Otherwise return BUFMAPNOTFOUND.
  const Status lookup(File* file, const int pageNo, unsigned int & frameNo) const;

  // delete entry (file,pageNo) from buffer pool.  Return OK if page was
  // found.  Else return BUFMAPNOTFOUND.
  const Status remove(File* file, const int pageNo);
  
  // Get the map for the file*, and then you can go over all the pages of that file in the buffer pool
  // Return that Ponter and OK on success
  const Status maplookup(File* file, PageMapPtr& pageMap) const;

};

#endif
